package com.amado.course50java8;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import com.amado.course50java8.vo.Goods;

public class Java806Optional3Filter {
	public static void main(String[] args) {
		//filter是过滤条件，如果不满足返回一个empty Optional
		System.out.println(Optional.ofNullable(new Goods("鞋子")).map(t -> t.getGoodsName()).filter(c -> c.contains("d"))
				.orElse(null));
		
		
		List<String> list = Arrays.asList("ab","bc","cd");
		System.out.println(list(list));
	}
	public static List<String> list(List<String> list) {
		List<String> strList = new ArrayList<>();
		for(String str:list) {
			if(str.contains("b")) {
				strList.add(str);
			}
		}
		return strList;
	}
	public static List<String> listJava8(List<String> list) {
		List<String> strList = new ArrayList<>();
		for(String str:list) {
			Optional.ofNullable(str).filter((e)->e.contains("b")).orElse(null);
		}
		return strList;
	}
}
